<?php
$baseUrl = Yii::app()->request->baseUrl;
?>

<!-- http://www.yiiframework.com/doc/guide/1.1/en/form.table yii tabular input -->
<li style="<?php echo $index==0 ? 'display:block' : 'display:none' ?>">
<div class="form">

    <?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'offer-form',
    'enableAjaxValidation'=>false,
)); ?>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <div data-role="fieldcontain">
            <?php echo $form->labelEx($model,"offer_name"); ?>
            <fieldset data-role="controlgroup">
            <?php echo $form->textField($model,"[$index]offer_name",array('size'=>50,'maxlength'=>50,"x-webkit-speech speech"=>'')); ?>
            <?php echo $form->error($model,"[$index]offer_name"); ?>
            </fieldset>
        </div>
    </div>

    <div class="row">
        <div data-role="fieldcontain">
            <?php echo $form->labelEx($model,"price"); ?>
            <fieldset data-role="controlgroup">
            <?php echo $form->textField($model,"[$index]price",array("x-webkit-speech speech"=>'')); ?>
            <?php echo $form->error($model,"[$index]price"); ?>
            </fieldset>
        </div>
    </div>

    <div class="row">
        <div data-role="fieldcontain">
            <?php echo $form->labelEx($model,"offer_detail"); ?>
            <fieldset data-role="controlgroup">
            <?php echo $form->textArea($model,"[$index]offer_detail",array('rows'=>6, 'cols'=>50)); ?>
            <?php echo $form->error($model,"[$index]offer_detail"); ?>
            </fieldset>
        </div>
    </div>

    <!-- In order to make mobiscroll plugin working with tabular input, textField's id must follow this format input name="Offer[0][start_date]" id="Offer_0_start_date" -->
    <div class="row">
        <div data-role="fieldcontain" data-mini="true">
            <?php echo $form->labelEx($model,"start_date"); ?>
            <fieldset data-role="controlgroup">
            <?php echo $form->textField($model,"[$index]start_date", array('id'=>"Offer_".$index."_start_date", 'name'=>"Offer[$index][start_date]")); ?>
            <?php echo $form->error($model,"[$index]start_date"); ?>
            </fieldset>
        </div>
    </div>

    <!-- In order to make mobiscroll plugin working with tabular input, textField's id must follow this format input name="Offer[0][expiry_date]" id="Offer_0_expiry_date" -->
    <div class="row">
        <div data-role="fieldcontain" data-mini="true">
            <?php echo $form->labelEx($model,"expiry_date"); ?>
            <fieldset data-role="controlgroup">
            <?php echo $form->textField($model,"[$index]expiry_date", array('id'=>"Offer_".$index."_expiry_date", 'name'=>"Offer[$index][expiry_date]")); ?>
            <?php echo $form->error($model,"[$index]expiry_date"); ?>
            </fieldset>
        </div>
    </div>

    <div class="row">
        <div data-role="fieldcontain">
            <?php echo $form->labelEx($model,"offer_status"); ?>
            <fieldset data-role="controlgroup" data-type="horizontal">
                <?php echo $form->radioButtonList($model,"[$index]offer_status", array('1'=>'ON', '0'=>'OFF'),array('separator'=>'')); ?>
                <?php echo $form->error($model,"[$index]offer_status"); ?>
                <?php echo $form->textField($model,"[$index]image_id",array('size'=>50,'maxlength'=>50, 'readonly'=>true, 'id'=>"fname$index")); ?>
                <?php echo $form->error($model,"[$index]image_id"); ?>
                <?php echo CHtml::submitButton('Save Offer', array("data-icon"=>"check", "data-inline"=>"true")); ?>
            </fieldset>
        </div>
    </div>

    <div class="row">
        <div data-role="fieldcontain">
              <span class="fileinput-button">
                  <!--if condition, if there is a file already, then disable upload button and enable delete button or vice versa-->
                  <?php
                  if($model->image_id == "default.jpg"){
                      echo CHtml::image("$baseUrl/images/Photos.png", 'upload', array('width'=>"42", 'height'=>"42", 'id'=>"Add$index"));
                      echo $form->fileField($model,"[$index]image_id",array('id'=>"fileupload$index", 'size'=>50,'maxlength'=>50, 'name'=>"files[]", 'data-url'=>"server/"));
                      echo ("</span>");
                      echo CHtml::image("$baseUrl/images/Delete.png", 'delete', array('width'=>"42", 'height'=>"42", 'id'=>"Del$index"));
                  }
                  else
                  {
                      echo CHtml::image("$baseUrl/images/Stack.png", 'upload', array('width'=>"42", 'height'=>"42", 'id'=>"Add$index"));
                      echo $form->fileField($model,"[$index]image_id",array('id'=>"fileupload$index", 'disabled'=>"true", 'size'=>50,'maxlength'=>50, 'name'=>"files[]", 'data-url'=>"server/"));
                      echo ("</span>");
                      echo CHtml::image("$baseUrl/images/Delete.png", 'delete', array('width'=>"42", 'height'=>"42", 'id'=>"Del$index", 'onClick'=>"Delete($index);"));
                  }

                  echo $form->error($model,"[$index]image_id");
                  ?>

                  <progress id="<?php echo "progBar".$index; ?>" value="0" max="100">Bar</progress>
        </div>
    </div>

<!--
There is more GUI design options, see extra GUIreference.txt file in GuiPlayGround
-->
    <?php $this->endWidget(); ?>

</div><!-- form -->

</li>
